<template>
	<view class="newsList-page">
		<template v-if="list.length>0">
			<view class="new-block" v-for="item in list" :key="item.id"
				@click="navigate('/pages/education/news_detail?id='+item.noticeId)">
				<view class="new-title">{{item.noticeTitle}}</view>
				<view class="new-text">{{item.createTime}}</view>
			</view>
		</template>
		<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
		<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
	</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getNoticesPageApi
	} from '@/api/home.js'
	export default {
		data() {
			return {
				topBgColor: 'rgba(0,0,0,0)',
				list: [],
				conf: {
					pageNum: 1,
					pageSize: 10,
					noticeType: 1
				},
				more: true,
			}
		},
		methods: {
			handleRefresh() {
				this.conf.pageNum = 1;
				this.more = true;
				this.getList(true);
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getNoticesPageApi(this.conf).then(res => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.pageNum, this.conf.pageSize, res.total)
				})
			}
		},
		onReachBottom() {
			if (this.more) {
				this.conf.pageNum++;
				this.getList();
			}
		},
		onLoad(e) {
			this.conf.noticeType = e.type
			this.getList(true)
		}
	}
</script>

<style lang="scss" scoped>
	.newsList-page {
		padding: 30rpx;

		.new-block {
			background-color: #fff;
			margin-bottom: 30rpx;
			border-radius: 20rpx;
			padding: 30rpx;

			.new-title {
				font-size: 32rpx;
				margin-bottom: 20rpx;
				word-break: break-all;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				/* 超出几行省略 */
				overflow: hidden;
			}

			.new-text {
				font-size: 28rpx;
				color: #767676;
			}
		}
	}
</style>